home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / bsktball.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  175 lines

  1. /***************************************************************************
  2.  
  3. Atari Basketball machine
  4.  
  5. If you have any questions about how this driver works, don't hesitate to
  6. ask.  - Mike Balfour (mab22@po.cwru.edu)
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int LD1=0;
  13. static int LD2=0;
  14. static unsigned int NMION = 0;
  15.  
  16. /***************************************************************************
  17. bsktball_nmion_w
  18. ***************************************************************************/
  19. WRITE_HANDLER( bsktball_nmion_w )
  20. {
  21.     NMION = offset & 0x01;
  22. }
  23.  
  24. /***************************************************************************
  25. bsktball_interrupt
  26. ***************************************************************************/
  27. /* NMI every 32V, IRQ every VBLANK */
  28. int bsktball_interrupt(void)
  29. {
  30.     static int i256V=0;
  31.  
  32.     /* We mod by 8 because we're interrupting 8x per frame, 1 per 32V */
  33.     i256V=(i256V+1) % 8;
  34.  
  35.     if (i256V==0)
  36.         return interrupt();
  37.     else if (NMION)
  38.         return nmi_interrupt();
  39.     else
  40.         return 0;
  41. }
  42.  
  43. /***************************************************************************
  44. bsktball_ld_w
  45. ***************************************************************************/
  46.  
  47. WRITE_HANDLER( bsktball_ld1_w )
  48. {
  49.     LD1 = (offset & 0x01);
  50. }
  51.  
  52. WRITE_HANDLER( bsktball_ld2_w )
  53. {
  54.     LD2 = (offset & 0x01);
  55. }
  56.  
  57.  
  58. /***************************************************************************
  59. bsktball_in0_r
  60. ***************************************************************************/
  61.  
  62. READ_HANDLER( bsktball_in0_r )
  63. {
  64.     static int DR0=0;        /* PL2 H DIR */
  65.     static int DR1=0;        /* PL2 V DIR */
  66.     static int DR2=0;        /* PL1 H DIR */
  67.     static int DR3=0;        /* PL1 V DIR */
  68.  
  69.     static int last_p1_horiz=0;
  70.     static int last_p1_vert=0;
  71.     static int last_p2_horiz=0;
  72.     static int last_p2_vert=0;
  73.  
  74.     int p1_horiz;
  75.     int p1_vert;
  76.     int p2_horiz;
  77.     int p2_vert;
  78.     int temp;
  79.  
  80.     p1_horiz = input_port_0_r(offset);
  81.     p1_vert  = input_port_1_r(offset);
  82.     p2_horiz = input_port_2_r(offset);
  83.     p2_vert  = input_port_3_r(offset);
  84.  
  85.     /* Set direction bits */
  86.  
  87.     /* P1 H DIR */
  88.     if (p1_horiz > last_p1_horiz)
  89.     {
  90.         if ((p1_horiz-last_p1_horiz) > 128)        DR2=0x40;
  91.         else                                    DR2=0;
  92.     }
  93.     else if (p1_horiz < last_p1_horiz)
  94.     {
  95.         if ((last_p1_horiz-p1_horiz) > 128)        DR2=0;
  96.         else                                    DR2=0x40;
  97.     }
  98.  
  99.     /* P1 V DIR */
  100.     if (p1_vert > last_p1_vert)
  101.     {
  102.         if ((p1_vert-last_p1_vert) > 128)        DR3=0;
  103.         else                                    DR3=0x80;
  104.     }
  105.     else if (p1_vert < last_p1_vert)
  106.     {
  107.         if ((last_p1_vert-p1_vert) > 128)        DR3=0x80;
  108.         else                                    DR3=0;
  109.     }
  110.  
  111.     /* P2 H DIR */
  112.     if (p2_horiz > last_p2_horiz)
  113.     {
  114.         if ((p2_horiz-last_p2_horiz) > 128)        DR0=0x10;
  115.         else                                    DR0=0;
  116.     }
  117.     else if (p2_horiz < last_p2_horiz)
  118.     {
  119.         if ((last_p2_horiz-p2_horiz) > 128)        DR0=0;
  120.         else                                    DR0=0x10;
  121.     }
  122.  
  123.     /* P2 V DIR */
  124.     if (p2_vert > last_p2_vert)
  125.     {
  126.         if ((p2_vert-last_p2_vert) > 128)        DR1=0;
  127.         else                                    DR1=0x20;
  128.     }
  129.     else if (p2_vert < last_p2_vert)
  130.     {
  131.         if ((last_p2_vert-p2_vert) > 128)        DR1=0x20;
  132.         else                                    DR1=0;
  133.     }
  134.  
  135.  
  136.     last_p1_horiz = p1_horiz;
  137.     last_p1_vert  = p1_vert;
  138.     last_p2_horiz = p2_horiz;
  139.     last_p2_vert  = p2_vert;
  140.  
  141.     /* D0-D3 = Plyr 1 Horiz, D4-D7 = Plyr 1 Vert */
  142.     if ((LD1) & (LD2))
  143.     {
  144.         return ((p1_horiz & 0x0F) | ((p1_vert << 4) & 0xF0));
  145.     }
  146.     /* D0-D3 = Plyr 2 Horiz, D4-D7 = Plyr 2 Vert */
  147.     else if (LD2)
  148.     {
  149.         return ((p2_horiz & 0x0F) | ((p2_vert << 4) & 0xF0));
  150.     }
  151.     else
  152.     {
  153.         temp = input_port_4_r(offset) & 0x0F;
  154.         /* Remap button 1 back to the Start button */
  155.         /* NOTE:  This is an ADDED feature, not a part of the original hardware! */
  156.         temp = (temp) & (temp>>2);
  157.  
  158.         return (temp | DR0 | DR1 | DR2 | DR3);
  159.     }
  160. }
  161.  
  162. /***************************************************************************
  163. bsktball_led_w
  164. ***************************************************************************/
  165. WRITE_HANDLER( bsktball_led1_w )
  166. {
  167.         osd_led_w(0,(offset & 0x01));
  168. }
  169.  
  170. WRITE_HANDLER( bsktball_led2_w )
  171. {
  172.         osd_led_w(1,(offset & 0x01));
  173. }
  174.  
  175.